<?php
defined('BASEPATH') OR exit('No direct script access allowed');


use QCloud_WeApp_SDK\Mysql\Mysql as DB;


class AddressUpdate extends CI_Controller
{
    public function index()
    {
        $userid = $_POST['userid'];
        $id = $_POST['id'];
        $name = $_POST['name'];
        $tel = $_POST['tel'];
        $province = $_POST['province'];
        $city = $_POST['city'];
        $area = $_POST['area'];
        $address = $_POST['address'];
        $status = $_POST['status'];

        if ($status == 1) {
            DB::update('cc_address', [
                'status' => 0], ['userid' => $userid]);
        }

        $rows = DB::update('cc_address', [
            'name' => $name, 'tel' => $tel, 'province' => $province, 'city' => $city,
            'area' => $area, 'address' => $address, 'status' => $status],
            ['id' => $id]);

        if ($rows > 0) {
            $this->json([
                'code' => 0,
                'data' => $rows
            ]);
        } else {
            $this->json([
                'code' => -1,
                'error' => $rows['error']
            ]);
        }
    }
}
